package com.helloworld.controller;

import com.helloworld.pojo.User_Role;
import com.helloworld.service.User_RoleService;
import com.helloworld.vo.HttpResponse;
import com.helloworld.vo.User.UserAddReq;
import com.helloworld.vo.User.UserListReq;
import com.helloworld.vo.User.UserUpdateReq;
import com.helloworld.vo.User_Role.User_RoleAddReq;
import com.helloworld.vo.User_Role.User_RoleUpdateReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userRole")
public class User_RoleController {

    @Autowired
    private User_RoleService user_roleService;

    @GetMapping({"/Info"})
    public HttpResponse queryUser_RoleList(Integer id){
        return HttpResponse.suc(user_roleService);
    }

    @GetMapping({"/list"})
    public HttpResponse list(UserListReq req){
        return HttpResponse.suc(user_roleService.queryUser_RoleList(req.getNameLike()));
    }

    @PostMapping({"/add"})
    public HttpResponse addUser(@RequestBody User_RoleAddReq req){
        Integer id = user_roleService.addUser_Role(req);
        return HttpResponse.suc(user_roleService.queryUser_RoleById(id));
    }

    @PostMapping({"/update"})
    public HttpResponse update(@RequestBody User_RoleUpdateReq req){
        user_roleService.updateUser_Role(req);
        return HttpResponse.suc(user_roleService.queryUser_RoleById(req.getId()));
    }

    @PostMapping({"/delete"})
    public HttpResponse deleteUser(Integer id){
        user_roleService.deleteUser_Role(id);
        return HttpResponse.suc(null);
    }
}
